package com.sjz.myfrist;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/****
 * *如何使用按钮和图片（点击事件、长按点击、同时展示文本和图像、ImageView）
 */
public class BasicButtonCase extends AppCompatActivity implements View.OnClickListener{
    private TextView tv_result;
    private Button test_btn_click_single;
    private Button jinyonganniu;
    private Button qiyonganniu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.basic_button_case);


        tv_result=findViewById(R.id.test_tv_result);
        test_btn_click_single= findViewById(R.id.test_btn_click_single);
        jinyonganniu=findViewById(R.id.jinyonganniu);
        qiyonganniu=findViewById(R.id.qiyonganniu);

        test_btn_click_single.setOnClickListener(this);
        jinyonganniu.setOnClickListener(this);
        qiyonganniu.setOnClickListener(this);


       // test_btn_click_single.setOnClickListener(new MyOnClickListener(tv_result)); //触发点击事件

        //长按按钮
        test_btn_click_single.setOnLongClickListener(v -> {   //匿名内部类
            String desc = String.format("您长按点击了按钮");
            tv_result.setText(desc);
            return true;//返回true则表示消耗掉长按，不再往上级视图传递，为false则长按会涉及到上级视图
        });

    }

    public void onClick(View v){
        switch (v.getId()){
            case R.id.qiyonganniu:
                test_btn_click_single.setEnabled(true);
                break;
            case R.id.jinyonganniu:
                test_btn_click_single.setEnabled(false);
                break;
            case R.id.test_btn_click_single:
                String desc = String.format("点击了按钮");
                tv_result.setText(desc);
                break;
        }
    }
    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {
        super.onPointerCaptureChanged(hasCapture);
    }
  

    /*//点击事件  创建类实现接口
    class MyOnClickListener implements View.OnClickListener{

        private final TextView tv_result;
        public MyOnClickListener(TextView tv_result){//构造函数
            this.tv_result = tv_result;
        }

        @Override
        public void onClick(View v) {
            String desc = String.format("您点击了按钮");
            tv_result.setText(desc);  //点击后直接赋值
        }
    }*/
}